package com.heeexy.example.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.service.EmpsService;
import com.heeexy.example.service.OrdersService;
import com.heeexy.example.util.CommonUtil;

@RestController
@RequestMapping("/orders")
public class OrdersController {
	 @Autowired
	  private OrdersService ordersService;
	 
	 @RequiresPermissions("sell:list")
	    @GetMapping("/listOrderO")
	    public JSONObject listOrderO(HttpServletRequest request) {
	        return ordersService.listOrderO(CommonUtil.request2Json(request));
	    }
	 @RequiresPermissions("sell:list")
	    @GetMapping("/listOrderE")
	    public JSONObject listOrderE(HttpServletRequest request) {
	        return ordersService.listOrderE(CommonUtil.request2Json(request));
	    }
	 
	 @RequiresPermissions("sell:list")
	    @GetMapping("/list")
	    public JSONObject list(HttpServletRequest request) {
	        return ordersService.listOrders(CommonUtil.request2Json(request));
	    }
	 
	 @RequiresPermissions("sell:update")
	    @PostMapping("/updateOrders")
	    public JSONObject updateGoods(@RequestBody JSONObject requestJson) {
	       CommonUtil.hasAllRequired(requestJson, "oid,odate,gid,cid,eid,otype,onumber,oprice");
	        return ordersService.updateOrders(requestJson);
	    }

	 @RequiresPermissions("sell:add")
	    @PostMapping("/addOrders")
	    public JSONObject addUser(@RequestBody JSONObject requestJson) {
	        CommonUtil.hasAllRequired(requestJson, "oid,odate,gid,cid,eid,otype,onumber,oprice");
	        return ordersService.addOrders(requestJson);
	    }
	 
	 @RequiresPermissions("sell:delete")
	    @PostMapping("/deleteOrders")
	    public JSONObject deleteRole(@RequestBody JSONObject requestJson) {
	        CommonUtil.hasAllRequired(requestJson,"eid");
	        return ordersService.deleteOrders(requestJson);
	    }

}
